<template>
    <div class="ct-bodySet">
        <el-container>
            <el-header class="bgclr-dk-sp0 mb20 headerCoster">
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/mainPage/welcome' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>日报管理</el-breadcrumb-item>
                    <el-breadcrumb-item><span class="main-Clr-ft">工作明细</span></el-breadcrumb-item>
                </el-breadcrumb>

            </el-header>
            <div class="pl20 pr20">
                <el-card class="mb20 cardWidth">
                    <el-form :inline="true"  :model="formData" ref="formData" class="noMarginBottom">
                        <el-form-item  class="mb1">
                            <div class="block" >
                                <span class="demonstration">周</span>
                                <el-date-picker id = "weekId"
                                        :picker-options="pickerOptions"
                                        editable =editable
                                         @change="modifyWeek"
                                        v-model="weekId"
                                        type="week"
                                        format="yyyy年 第 WW 周"
                                        placeholder="选择周"
                                        firstDayOfWeek='1'>
                                </el-date-picker>
                            </div>
                        </el-form-item>
                        <el-form-item>
                            <input id="startDate" type="text" v-model="startDate" class="def-el-input">
                            <span>~</span>
                            <input id="endDate" type="text" v-model="endDate" class="def-el-input">
                        </el-form-item>
                        <el-form-item class="mb1">
                            <el-button @click="lastOrNextWeek(-7)" size="small" class="bkmgColor">上周</el-button>
                        </el-form-item>
                        <el-form-item class="mb1">
                            <el-button type="primary" @click="nowWeek()" size="small" >本周</el-button>
                        </el-form-item>
                        <el-form-item class="mb1">
                            <el-button  @click="lastOrNextWeek(7)" size="small" class="bkmgColor">下周</el-button>
                        </el-form-item>
                        <el-form-item class="mb1">
                            <el-button  @click="noSubmitPersonMessage()" size="small" class="bkmgColor">提醒</el-button>
                        </el-form-item>
<!--                        <el-form-item class="mb1">-->
<!--                            <el-button  @click="sendMail()" size="small" class="bkmgColor">sendTo</el-button>-->
<!--                        </el-form-item>-->
                        <el-form-item   class="mb1 fltRt">
                            <el-button v-show="roleId=='10002'" @click="editWeekSummary(true)" size="small" class="bkmgColor">编辑本周工作概述</el-button>
                            <el-button v-show="roleId=='10004'" @click="editWeekSummary(false)" size="small" class="bkmgColor">查看本周工作概述</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
                <el-card class="mb20 cardWidth">
                    <div slot="header">
                        <span>一、本周研发工作</span><span style="color: red">（建议填写工作内容时，不要填写编号，即使填写也会被处理掉。）</span>
                        <el-button  style="float: right; padding: 3px 0" type="text" @click="submitProduct()">提交</el-button>
                    </div>
                    <el-col :span="1">
                        <div class="fltLt">
                            <p><el-button  type="text" style="font-weight: bold;font-size: 18px" class="el-icon-plus" @click="addProductRow()" ></el-button></p>
                        </div>
                    </el-col>
                    <el-col :span="23">
                    <el-table
                            ref="multipleTable"
                            border
                            stripe
                            :header-cell-style="getRowClass"
                            tooltip-effect="dark"
                            :data="weekDetail.productWeek">
                        <el-table-column  label="任务"  :prop="taskInfo" min-width="27%" height=200>
                            <template slot-scope="scope">
                                     <span v-if="scope.row.editSet">
                                         <el-select v-model="scope.row.taskInfo" ref="formData.productSelected">
                                            <el-option
                                                    v-for="item1 in formData.productAll"
                                                    :label="item1.value"
                                                    :value="item1">
                                            </el-option>
                                         </el-select>
                                     </span>
                                     <span v-else>
                                         <div>{{scope.row.taskInfo.value}}</div>
                                     </span>
                            </template>
                        </el-table-column>
                        <el-table-column  label="负责人"  :prop="userInfo" min-width="13%" height=200>
                            <template slot-scope="scope">
                                  <span v-if="scope.row.editSet">
                                     <el-select v-model="scope.row.userInfo"  multiple ref="formData.userSelected">
                                        <el-option
                                                v-for="item2 in formData.userAll"
                                                :label="item2.value"
                                                :value="item2">
                                        </el-option>
                                     </el-select>
                                  </span>
                                 <span v-else>
                                     <div v-for="item3 in scope.row.userInfo">{{item3.value}}</div>
                                 </span>
                            </template>
                        </el-table-column>
                        <el-table-column  style="color: #2FB2B8;" label="工作内容"  :prop="workContent" min-width="50%" >
                            <template slot-scope="scope">
                                      <span v-if="scope.row.editSet">
                                         <el-input type="textarea" :autosize="{ minRows: 2}"  v-model="scope.row.workContent">
                                         </el-input>
                                      </span>
                                      <div  style="white-space:pre-wrap;" v-else>{{scope.row.workContent}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column   label="操作" min-width='10%' align="center">
                            <template slot-scope="scope">
                                <el-button  title="编辑" type="text" size="small" @click="editProductRow(scope.row,scope.$index)" icon="iconfont icon-bianji"></el-button>
                                <el-button  title="删除" class="deleteButtonColor" type="text" size="small" @click="deleteRow(weekDetail.productWeek,scope.$index)" icon="iconfont icon-shanchu"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    </el-col>
                    <el-col :span="24">
                        <div><br></div>
                    </el-col>
                </el-card>
                <el-card class="mb20 cardWidth">
                    <div slot="header" class="clearfix">
                        <span>二、本周项目支持</span>
                        <el-button style="float: right; padding: 3px 0" type="text" @click="submitProject()">提交</el-button>
                    </div>
                    <el-col :span="1">
                        <div class="fltLt">
                            <p><el-button  type="text" style="font-weight: bold;font-size: 18px" class="el-icon-plus" @click="addProjectRow()" ></el-button></p>
                        </div>
                    </el-col>
                    <el-col :span="23">
                        <el-table
                                ref="multipleTable"
                                border
                                stripe
                                :header-cell-style="getRowClass"
                                tooltip-effect="dark"
                                :data="weekDetail.projectWeek">
                            <el-table-column  label="任务"  :prop="taskInfo" min-width="27%" height=200>
                                <template slot-scope="scope">
                                     <span v-if="scope.row.editSet">
                                         <el-select v-model="scope.row.taskInfo" ref="formData.projectSelected">
                                            <el-option
                                                    v-for="item1 in formData.projectAll"
                                                    :label="item1.value"
                                                    :value="item1">
                                            </el-option>
                                         </el-select>
                                     </span>
                                    <span v-else>
                                         <div>{{scope.row.taskInfo.value}}</div>
                                    </span>
                                </template>
                            </el-table-column>
                            <el-table-column  label="负责人"  :prop="userInfo" min-width="13%" height=200>
                                <template slot-scope="scope">
                                  <span v-if="scope.row.editSet">
                                     <el-select v-model="scope.row.userInfo" multiple ref="formData.userSelected">
                                        <el-option
                                                v-for="item2 in formData.userAll"
                                                :label="item2.value"
                                                :value="item2">
                                        </el-option>
                                     </el-select>
                                  </span>
                                    <span v-else>
                                     <div v-for="item3 in scope.row.userInfo">{{item3.value}}</div>
                                 </span>
                                </template>
                            </el-table-column>
                            <el-table-column  style="color: #2FB2B8;" label="工作内容"  :prop="workContent" min-width="50%" >
                                <template slot-scope="scope">
                                      <span v-if="scope.row.editSet">
                                         <el-input type="textarea" :autosize="{ minRows: 2}"  v-model="scope.row.workContent">
                                         </el-input>
                                      </span>
                                    <div  style="white-space:pre-wrap;" v-else>{{scope.row.workContent}}</div>
                                </template>
                            </el-table-column>
                            <el-table-column  label="操作" min-width='10%' align="center">
                                <template slot-scope="scope">
                                    <el-button title="编辑" type="text" size="small" @click="editProjectRow(scope.row,scope.$index)" icon="iconfont icon-bianji"></el-button>
                                    <el-button title="删除" class="deleteButtonColor" type="text" size="small" @click="deleteRow(weekDetail.projectWeek,scope.$index)" icon="iconfont icon-shanchu"></el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                    <el-col :span="24">
                        <div><br></div>
                    </el-col>
                </el-card>
                <el-card class="mb20 cardWidth">
                    <div slot="header" class="clearfix">
                        <span>三、下周研发计划</span>
                        <el-button  style="float: right; padding: 3px 0" type="text" @click="submitNextProduct()">提交</el-button>
                    </div>
                    <el-col :span="1">
                        <div class="fltLt">
                            <p><el-button  type="text" style="font-weight: bold;font-size: 18px" class="el-icon-plus" @click="addNextProductRow()" ></el-button></p>
                        </div>
                    </el-col>
                    <el-col :span="23">
                        <el-table
                                ref="multipleTable"
                                border
                                stripe
                                :header-cell-style="getRowClass"
                                tooltip-effect="dark"
                                :data="weekDetail.nextProductWeek">
                            <el-table-column  label="任务"  :prop="taskInfo" min-width="27%" height=200>
                                <template slot-scope="scope">
                                     <span v-if="scope.row.editSet">
                                         <el-select v-model="scope.row.taskInfo" ref="formData.productSelected">
                                            <el-option
                                                    v-for="item1 in formData.productAll"
                                                    :label="item1.value"
                                                    :value="item1">
                                            </el-option>
                                         </el-select>
                                     </span>
                                    <span v-else>
                                         <div>{{scope.row.taskInfo.value}}</div>
                                    </span>
                                </template>
                            </el-table-column>
                            <el-table-column  label="负责人"  :prop="userInfo" min-width="13%" height=200>
                                <template slot-scope="scope">
                                  <span v-if="scope.row.editSet">
                                     <el-select v-model="scope.row.userInfo" multiple ref="formData.userSelected">
                                        <el-option
                                                v-for="item2 in formData.userAll"
                                                :label="item2.value"
                                                :value="item2">
                                        </el-option>
                                     </el-select>
                                  </span>
                                    <span v-else>
                                     <div v-for="item3 in scope.row.userInfo">{{item3.value}}</div>
                                 </span>
                                </template>
                            </el-table-column>
                            <el-table-column  style="color: #2FB2B8;" label="工作内容"  :prop="workContent" min-width="50%" >
                                <template slot-scope="scope">
                                      <span v-if="scope.row.editSet">
                                         <el-input type="textarea" :autosize="{ minRows: 2}"   v-model="scope.row.workContent">
                                         </el-input>
                                      </span>
                                    <div  style="white-space:pre-wrap;" v-else>{{scope.row.workContent}}</div>
                                </template>
                            </el-table-column>
                            <el-table-column  label="操作" min-width='10%' align="center">
                                <template slot-scope="scope">
                                    <el-button title="编辑" type="text" size="small" @click="editNextProductRow(scope.row,scope.$index)" icon="iconfont icon-bianji"></el-button>
                                    <el-button title="删除" class="deleteButtonColor" type="text" size="small" @click="deleteRow(weekDetail.nextProductWeek,scope.$index)" icon="iconfont icon-shanchu"></el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                    <el-col :span="24">
                        <div><br></div>
                    </el-col>
                </el-card>
                <el-card class="mb20 cardWidth">
                    <div slot="header" class="clearfix">
                        <span>四、下周项目支持</span>
                        <el-button  style="float: right; padding: 3px 0" type="text" @click="submitNextProject()">提交</el-button>
                    </div>
                    <el-col :span="1">
                        <div class="fltLt">
                            <p><el-button  type="text" style="font-weight: bold;font-size: 18px" class="el-icon-plus" @click="addNextProjectRow()" ></el-button></p>
                        </div>
                    </el-col>
                    <el-col :span="23">
                        <el-table
                                ref="multipleTable"
                                border
                                stripe
                                :header-cell-style="getRowClass"
                                tooltip-effect="dark"
                                :data="weekDetail.nextProjectWeek">
                            <el-table-column  label="任务"  :prop="taskInfo" min-width="27%" height=200>
                                <template slot-scope="scope">
                                     <span v-if="scope.row.editSet">
                                         <el-select v-model="scope.row.taskInfo"  ref="formData.projectSelected">
                                            <el-option
                                                    v-for="item1 in formData.projectAll"
                                                    :label="item1.value"
                                                    :value="item1">
                                            </el-option>
                                         </el-select>
                                     </span>
                                    <span v-else>
                                         <div>{{scope.row.taskInfo.value}}</div>
                                    </span>
                                </template>
                            </el-table-column>
                            <el-table-column  label="负责人"  :prop="userInfo" min-width="13%" height=200>
                                <template slot-scope="scope">
                                  <span v-if="scope.row.editSet">
                                     <el-select v-model="scope.row.userInfo" multiple ref="formData.userSelected">
                                        <el-option
                                                v-for="item2 in formData.userAll"
                                                :label="item2.value"
                                                :value="item2">
                                        </el-option>
                                     </el-select>
                                  </span>
                                    <span v-else>
                                        <div v-for="item3 in scope.row.userInfo">{{item3.value}}</div>
                                 </span>
                                </template>
                            </el-table-column>
                            <el-table-column  style="color: #2FB2B8;" label="工作内容"  :prop="workContent" min-width="50%" >
                                <template slot-scope="scope">
                                      <span v-if="scope.row.editSet">
                                         <el-input type="textarea" :autosize="{ minRows: 2}"  v-model="scope.row.workContent"></el-input>
                                      </span>
                                    <div  style="white-space:pre-wrap;" v-else>{{scope.row.workContent}}</div>
                                </template>
                            </el-table-column>
                            <el-table-column  label="操作" min-width='10%' align="center">
                                <template slot-scope="scope">
                                    <el-button title="编辑" type="text" size="small" @click="editProjectRow(scope.row,scope.$index)" icon="iconfont icon-bianji"></el-button>
                                    <el-button title="删除" class="deleteButtonColor" type="text" size="small" @click="deleteRow(weekDetail.nextProjectWeek,scope.$index)" icon="iconfont icon-shanchu"></el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                    <el-col :span="24">
                        <div><br></div>
                    </el-col>
                </el-card>
            </div>
            <div class="bottomLayoutBus"></div>
<!--            <span>{{weekDetail.productWeek}}</span>-->
        </el-container>

    </div>
</template>

<script>
    import urlConfig from '../../../config/url.json';
    import Vue from 'vue';
    import { Message } from 'element-ui';
    Vue.component(Message.name, Message);

    let productUrl=urlConfig.productManage;
    let weekDetailUrl = urlConfig.weekDetailManage;
    let addWeekDetailUrl = urlConfig.addWeekDetailUrl;
    let sendMailUrl = urlConfig.sendMailUrl;

    export default {
        name: '',
        data() {
            return {
                pickerOptions: {
                    firstDayOfWeek:1,
                    },
                htmlContent:'',
                weekId:'',
                MutiSelect:'',
                formData: {
                    userName:'',
                    productAll:[],
                    productSelected:[],
                    projectAll:[],
                    projectSelected:[],
                    userAll:'',
                    userSelected:[]
                },
                showData:{
                    showProductSelect:[],
                    showUserSelected:[],
                },
                weekDetail: {
                    productWeek:[],
                    projectWeek:[],
                    nextProductWeek:[],
                    nextProjectWeek:[]
                },
                editable:false,
                taskInfo:"",
                userInfo:"",
                workContent:"",
                roleId:"",
                startDate:"",
                endDate:"",
                weekSubmitCount:"",
                weekNoSubmitCount:"",
                NextSubmitCount:"",
                NextNoSubmitCount:"",
                weekNoSubmitPerson:[],
                nextNoSubmitPerson:[]
            }
        },
        methods: {
            sendMail(){
                debugger;
                let that=this;
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                });
                that.$http({
                    method: 'post',
                    url: sendMailUrl,
                    baseURL:'/api',
                    data:{
                        'sendtitle':'',
                        'receiverList':[],
                        'contactList':[],
                        'mailContent':"周报填写情况通告"

                    }
                }).then(function(response){
                    if(response.data.code==200){
                        Message.success("发送邮件成功！")
                    }
                    else{
                        Message.error('发送邮件失败');
                    }
                    loading.close();
                }).catch(function(err){
                    console.log(err);
                    Message.error('发送邮件失败');
                    loading.close();
                });
            },
            modifyWeek(){
                let that = this;
                that.getMonDayAndSunDay(that.weekId);
            },
            editWeekSummary(editFlag){
                let that = this;
                for(var i=0;i<that.weekDetail.productWeek.length;i++){
                    if(that.weekDetail.productWeek[i].editSet==true){
                        Message.warning("请先提交本周研发任务");
                        return;
                    }
                }
                for(var i=0;i<that.weekDetail.projectWeek.length;i++){
                    if(that.weekDetail.projectWeek[i].editSet==true){
                        Message.warning("请先提交本周项目支持");
                        return;
                    }
                }
                if(that.weekDetail.productWeek.length==0&&that.weekDetail.projectWeek.length==0){
                    Message.warning("请先填写本周的的研发任务和项目支持")
                }
                else{
                    var userIdList = new Array();
                    for(var i=0;i<that.formData.userAll.length;i++){
                        userIdList.push(that.formData.userAll[i].code);
                    }
                    that.$router.push({
                        path:'/mainPage/weekBusiness/weekSummary',
                        query: {
                            "weekId":that.getWeekId(),
                            "productWeek":that.productSummary(),
                            "productCount":that.weekDetail.productWeek.length,
                            "projectWeek":that.projectSummary(),
                            "projectCount":that.weekDetail.projectWeek.length,
                            "userIdList":userIdList,
                            "editFlag":editFlag,
                            "roleId":that.roleId,
                            "week":document.getElementById("weekId").value,
                            "startDate":document.getElementById("startDate").value,
                            "endDate":document.getElementById("endDate").value,
                            "year":document.getElementById("weekId").value.substring(0,4)
                        }
                    })
                }
            },
            productSummary(){
                let that=this;
                var productWeek = new Array();
                var productDetail = that.weekDetail.productWeek;
                for(var i=0;i<productDetail.length;i++){
                    var map={
                        "taskId":productDetail[i].taskInfo.code,
                        "taskName":productDetail[i].taskInfo.value,
                        "workSummaryList":[{"groupId":productDetail[i].userInfo[0].groupId,"workContent":""},],
                        "editSet":true
                    };
                    if(productWeek.length==0){
                        productWeek.push(map);
                    }else{
                        for(var j=0;j<productWeek.length;j++){
                            if(productDetail[i].taskInfo.code==productWeek[j].taskId){
                                var workContentList = productWeek[j].workSummaryList;
                                for(var k=0;k<workContentList.length;k++){
                                    if(workContentList[k].groupId==productDetail[i].userInfo[0].groupId){
                                        break;
                                    }else{
                                        if(workContentList.length-1==k){
                                            workContentList.push({"groupId":productDetail[i].userInfo[0].groupId,"workContent":""})
                                        }else{
                                            continue;
                                        }
                                    }
                                }

                                break;
                            }else{
                                if(productWeek.length-1==j){
                                    productWeek.push(map);
                                    break;
                                }else{
                                    continue;
                                }
                            }
                        }
                    }

                }
                debugger;
                return productWeek;
            },
            projectSummary(){
                let that=this;
                var projectWeek = new Array();
                var projectDetail = that.weekDetail.projectWeek;
                for(var i=0;i<projectDetail.length;i++){
                    var map={
                        "taskId":projectDetail[i].taskInfo.code,
                        "taskName":projectDetail[i].taskInfo.value,
                        "workSummaryList":[{"groupId":projectDetail[i].userInfo[0].groupId,"workContent":""},],
                        "editSet":true
                    };
                    if(projectWeek.length==0){
                        projectWeek.push(map);
                    }else{
                        for(var j=0;j<projectWeek.length;j++){
                            if(projectDetail[i].taskInfo.code==projectWeek[j].taskId){
                                var workContentList = projectWeek[j].workSummaryList;
                                for(var k=0;k<workContentList.length;k++){
                                    if(workContentList[k].groupId==projectDetail[i].userInfo[0].groupId){
                                        break;
                                    }else{
                                        if(workContentList.length-1==k){
                                            workContentList.push({"groupId":projectDetail[i].userInfo[0].groupId,"workContent":""})
                                        }else{
                                            continue;
                                        }
                                    }
                                }

                                break;
                            }else{
                                if(projectWeek.length-1==j){
                                    projectWeek.push(map);
                                    break;
                                }else{
                                    continue;
                                }
                            }
                        }
                    }

                }
                return projectWeek;
            },
            uuid() {
                var s = [];
                var hexDigits = "0123456789abcdef";
                for (var i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
                s[8] = s[13] = s[18] = s[23] = "-";

                var uuid = s.join("");
                return uuid;
            },
            addProductRow() {
                let that= this;
                if(that.roleId=="10003"){
                    var code = JSON.parse(that.STORAGE.getItem("userAll"))[0].code;
                    var value = JSON.parse(that.STORAGE.getItem("userAll"))[0].value;
                    var groupId = JSON.parse(that.STORAGE.getItem("userAll"))[0].groupId;

                    let j = {
                        'colid':'',
                        "taskInfo":{},
                        "userInfo": [{"code":code,"value":value,"groupId":groupId},],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.productWeek.splice(0,0,j);
                }else{
                    let j = {
                        'colid':'',
                        "taskInfo":{},
                        "userInfo": [],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.productWeek.splice(0,0,j);
                }
            },
            addProjectRow(){
                let that= this;
                if(that.roleId=="10003") {
                    var code = JSON.parse(that.STORAGE.getItem("userAll"))[0].code;
                    var value = JSON.parse(that.STORAGE.getItem("userAll"))[0].value;
                    var groupId = JSON.parse(that.STORAGE.getItem("userAll"))[0].groupId;

                    let j = {
                        'colid':'',
                        "taskInfo": {},
                        "userInfo": [{"code":code,"value":value,"groupId":groupId},],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.projectWeek.splice(0, 0, j)
                }else{
                    let j = {
                        'colid':'',
                        "taskInfo":{},
                        "userInfo": [],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.projectWeek.splice(0, 0, j)
                }
            },
            addNextProductRow() {
                let that= this;
                if(that.roleId=="10003") {
                    var code = JSON.parse(that.STORAGE.getItem("userAll"))[0].code;
                    var value = JSON.parse(that.STORAGE.getItem("userAll"))[0].value;
                    var groupId = JSON.parse(that.STORAGE.getItem("userAll"))[0].groupId;

                    let j = {
                        'colid':'',
                        "taskInfo": {},
                        "userInfo": [{"code":code,"value":value,"groupId":groupId},],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.nextProductWeek.splice(0,0,j)
                }else{
                    let j = {
                        'colid':'',
                        "taskInfo":{},
                        "userInfo": [],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.nextProductWeek.splice(0, 0, j)
                }
            },
            addNextProjectRow(){
                let that= this;
                if(that.roleId=="10003") {
                    var code = JSON.parse(that.STORAGE.getItem("userAll"))[0].code;
                    var value = JSON.parse(that.STORAGE.getItem("userAll"))[0].value;
                    var groupId = JSON.parse(that.STORAGE.getItem("userAll"))[0].groupId;

                    let j = {
                        'colid':'',
                        "taskInfo": {},
                        "userInfo": [{"code":code,"value":value,"groupId":groupId},],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.nextProjectWeek.splice(0, 0, j);
                }else{
                    let j = {
                        'colid':'',
                        "taskInfo":{},
                        "userInfo": [],
                        "workContent": "",
                        "editSet": true,
                    };
                    that.weekDetail.nextProjectWeek.splice(0, 0, j)
                }
            },
            getRowClass({ rowIndex }) {
                if (rowIndex == 0) {
                    return 'background:#2FB2B8;color: white'
                } else {
                    return ''
                }
            },
            editProductRow(row) { //编辑
                let that= this;
                that.weekDetail.productWeek.sel = row;
                row.editSet = true

            },
            editProjectRow(row) { //编辑
                let that= this;
                that.weekDetail.projectWeek.sel = row;
                row.editSet = true

            },
            editNextProductRow(row) { //编辑
                let that= this;
                that.weekDetail.nextProductWeek.sel = row;
                row.editSet = true

            },
            editNextProjectRow(row) { //编辑
                let that= this;
                that.weekDetail.nextProjectWeek.sel = row;
                row.editSet = true

            },
            deleteRow(rows,index) { //删除
                let that=this;
                var weekId=document.getElementById("weekId").value;
                weekId = that.getWeekId(weekId);
                if(rows[index].colid==""){
                    rows.splice(index, 1);
                    Message.success("删除周报成功！")
                }else{
                    const loading = this.$loading({
                        lock: true,
                        text: 'Loading',
                        spinner: 'el-icon-loading',
                    });
                    that.$http({
                        method: 'delete',
                        url: weekDetailUrl,
                        baseURL:'/api',
                        data:{
                            'colid':rows[index].colid,
                            'weekId':weekId,
                            'groupIdList':JSON.parse(that.STORAGE.getItem("groupIdList")),
                            'taskId':rows[index].taskInfo.code,
                            'userInfoList':rows[index].userInfo
                        }
                    }).then(function(response){
                        if(response.data.code==200){
                            that.queryWeekDetail(that.getWeekId());
                            Message.success("删除周报成功！")
                        }
                        else{
                            Message.error('删除周报失败');
                        }
                        loading.close();
                    }).catch(function(err){
                        console.log(err);
                        Message.error('删除周报失败');
                        loading.close();
                    });
                }
            },
            submitProduct(){
                let that = this;
                var arrList = new Array();
                for(var i=0;i<that.weekDetail.productWeek.length;i++){
                    if(that.weekDetail.productWeek[i].editSet==true){
                        if(that.weekDetail.productWeek[i].userInfo==""){
                            Message.warning("本周研发工作，请选择负责人！");
                            return;
                        }else if(that.weekDetail.productWeek[i].taskInfo==""){
                            Message.warning("本周研发工作，请选择任务！");
                            return;
                        }else if(that.weekDetail.productWeek[i].workContent==""){
                            Message.warning("本周研发工作，请填写工作内容！");
                            return;
                        }
                        else{
                            arrList.push(that.weekDetail.productWeek[i])
                        }
                    }
                }
                if(arrList.length==0){
                    Message.warning("没有要提交的本周研发工作！")
                }else{

                    that.submitWeekDetail("1",arrList);
                }
            },
            submitProject(){
                let that = this;
                var arrList = new Array();
                for(var i=0;i<that.weekDetail.projectWeek.length;i++){
                    if(that.weekDetail.projectWeek[i].editSet==true){
                        if(that.weekDetail.projectWeek[i].userInfo==""){
                            Message.warning("本周项目支持工作，请选择负责人！");
                            return;
                        }else if(that.weekDetail.projectWeek[i].taskInfo==""){
                            Message.warning("本周项目支持工作，请选择任务！");
                            return;
                        }else if(that.weekDetail.projectWeek[i].workContent==""){
                            Message.warning("本周项目支持工作，请填写工作内容！");
                            return;
                        }
                        else{
                            arrList.push(that.weekDetail.projectWeek[i])
                        }
                    }
                }
                if(arrList.length==0){
                    Message.warning("没有要提交的本周项目支持工作！")
                }else{
                    that.submitWeekDetail("2",arrList);
                }

            },
            submitNextProduct(){
                let that = this;
                var arrList = new Array();
                for(var i=0;i<that.weekDetail.nextProductWeek.length;i++){
                    if(that.weekDetail.nextProductWeek[i].editSet==true){
                        if(that.weekDetail.nextProductWeek[i].userInfo==""){
                            Message.warning("下周研发计划，请选择负责人！");
                            return;
                        }else if(that.weekDetail.nextProductWeek[i].taskInfo==""){
                            Message.warning("下周研发计划，请选择任务！");
                            return;
                        }else if(that.weekDetail.nextProductWeek[i].workContent==""){
                            Message.warning("下周研发计划，请填写工作内容！");
                            return;
                        }
                        else{
                            arrList.push(that.weekDetail.nextProductWeek[i])
                        }
                    }
                }
                if(arrList.length==0){
                    Message.warning("没有要提交的下周研发计划！")
                }else{
                    that.submitWeekDetail("3",arrList);
                }
            },
            submitNextProject(){
                let that = this;
                var arrList = new Array();
                for(var i=0;i<that.weekDetail.nextProjectWeek.length;i++){
                    if(that.weekDetail.nextProjectWeek[i].editSet==true){
                        if(that.weekDetail.nextProjectWeek[i].userInfo==""){
                            Message.warning("下周项目支持，请选择负责人！");
                            return;
                        }else if(that.weekDetail.nextProjectWeek[i].taskInfo==""){
                            Message.warning("下周项目支持，请选择任务！");
                            return;
                        }else if(that.weekDetail.nextProjectWeek[i].workContent==""){
                            Message.warning("下周项目支持，请填写工作内容！");
                            return;
                        }
                        else{
                            arrList.push(that.weekDetail.nextProjectWeek[i])
                        }
                    }
                }
                if(arrList.length==0){
                    Message.warning("没有要提交的下周项目支持工作！")
                }else{
                    that.submitWeekDetail("4",arrList);
                }
            },
            getWeekId(){
                let that = this;
               return that.startDate + "-" + that.endDate;
            },
            submitWeekDetail(taskType,arrList){
                debugger;
                let that=this;
                var weekId = document.getElementById("weekId").value;
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                });
                that.$http({
                    method: 'post',
                    url: addWeekDetailUrl,
                    baseURL:'/api',
                    data:{
                        'userId':JSON.parse(that.STORAGE.getItem("loginData"))['id'],
                        'weekDetailList':arrList,
                        'weekId':that.getWeekId(),
                        'taskType':taskType,
                        'userInfoList':that.formData.userAll
                    }
                }).then(function(response){
                    if(response.data.code==200){
                        that.queryWeekDetail(that.getWeekId());
                        Message.success("提交周报成功！")
                    }
                    else{
                        Message.error('提交周报失败');
                    }
                    loading.close();
                }).catch(function(err){
                    console.log(err);
                    Message.error('提交周报失败');
                    loading.close();
                });
            },
            nowWeek(){
                let that = this;
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var showWeek = year + "-" + month + "-"+ day;
                that.weekId = showWeek;
                that.getMonDayAndSunDay(that.weekId);
                that.queryWeekDetail(that.getWeekId());

            },
            lastOrNextWeek(num){
                let  that = this;
                var  showWeek = that.weekId;
                var showWeekDate = new Date(showWeek);
                showWeekDate.setDate(showWeekDate.getDate() +num);
                var showWeek = showWeekDate.getFullYear()+"-"+(showWeekDate.getMonth()+1)+"-"+showWeekDate.getDate();
                that.weekId = showWeek;
                that.getMonDayAndSunDay(that.weekId);
                that.queryWeekDetail(that.getWeekId());
            },
            queryWeekDetail(weekId){
                let that=this;
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                });
                that.$http({
                    method: 'post',
                    url: weekDetailUrl,
                    baseURL:'/api',
                    data:{
                        'userIdList':JSON.parse(that.STORAGE.getItem("userAll")),
                        'weekId':weekId
                    }
                }).then(function(response){
                    if(response.data.code==200){
                        debugger;
                        that.weekDetail.productWeek=response.data.data.productWeekDetailList;
                        that.weekDetail.projectWeek=response.data.data.projectWeekDetailList;
                        that.weekDetail.nextProductWeek=response.data.data.nextProductWeekDetailList;
                        that.weekDetail.nextProjectWeek=response.data.data.nextProjectWeekDetailList;
                        that.caculatePerson();
                        that.message();
                    }
                    else{
                        Message.error('获取数据失败');
                    }
                    loading.close();
                }).catch(function(err){
                    console.log(err);
                    Message.error('获取数据失败');
                    loading.close();
                });
            },
            getMonDayAndSunDay(datevalue){
                debugger;
                let that =this;
                var now = new Date(datevalue);
                var nowTime = now.getTime() ;
                var day = now.getDay();
                var oneDayTime = 24*60*60*1000 ;
                if(day==0){
                    day=7;
                    var MondayTime = nowTime - (day-1)*oneDayTime ;//显示周一
                    var SundayTime =  nowTime + (7-day)*oneDayTime ;//显示周日
                }else{
                    var MondayTime = nowTime - (day-1)*oneDayTime ;//显示周一
                    var SundayTime =  nowTime + (7-day)*oneDayTime ;//显示周日
                }


                var m = new Date(MondayTime);
                var mmonth = m.getMonth() + 1;
                var mday = m.getDate();
                if(mmonth < 10)
                    mmonth = "0" + mmonth;
                if(mday < 10){
                    mday = "0" + mday;
                }
                var mdatetime=m.getFullYear() + '-' + mmonth + '-' + mday;
                var s = new Date(SundayTime);
                var smonth = s.getMonth() + 1;
                var sday = s.getDate();
                if(smonth<10){
                    smonth = "0"+smonth;
                }
                if(sday<10){
                    sday = "0" + sday;
                }
                var sdatetime=s.getFullYear() + '-' + smonth + '-' + sday ;
                that.startDate=mdatetime;
                that.endDate=sdatetime;
            },
            message(){
                let that = this;
                var message ="";
                var noSubmitPerson="";
                var noSubmitNextPerson="";
                if(that.roleId=='10003'){
                    if(that.weekSubmitCount=='1'){
                        noSubmitPerson= '<div>本周周报： <span class="messageStyle1">'+"已提交本周周报"+'</span></div>';
                    }else{
                        noSubmitPerson= '<div>本周周报： <span class="messageStyle">'+"还未提交本周周报"+'</span></div>';
                    }
                    if(that.NextSubmitCount=='1'){
                        noSubmitNextPerson= '<div>下周计划： <span class="messageStyle1">'+"已提交下周计划"+'</span></div>';
                    }else{
                        noSubmitNextPerson= '<div>下周计划： <span class="messageStyle">'+"还未提交下周计划"+'</span></div>';
                    }
                    message = noSubmitPerson + noSubmitNextPerson;
                }else{
                    message = '<div>本周周报： 已有<span class="messageStyle1">'+that.weekSubmitCount+'</span>人提交周报，还有<span class="messageStyle">'+that.weekNoSubmitCount+'</span>人未提交周报</div>' +
                        '<div>下周计划： 已有<span class="messageStyle1">'+that.NextSubmitCount+'</span>人提交周报，还有<span class="messageStyle">'+that.NextNoSubmitCount+'</span>人未提交周报</div>';
                }
                that.$notify({
                    title: '提醒',
                    message:message ,
                    dangerouslyUseHTMLString:true,
                    offset: 50,
                    // duration: 0
                });
            },
            noSubmitPersonMessage(){
                debugger;
                let that = this;
                var message ="";
                var noSubmitPerson="";
                var noSubmitNextPerson="";

                if(that.roleId=='10003'){
                    if(that.weekSubmitCount=='1'){
                        noSubmitPerson= '<div>本周周报： <span class="messageStyle1">'+"已提交本周周报"+'</span></div>';
                    }else{
                        noSubmitPerson= '<div>本周周报： <span class="messageStyle">'+"还未提交本周周报"+'</span></div>';
                    }
                    if(that.NextSubmitCount=='1'){
                        noSubmitNextPerson= '<div>下周计划： <span class="messageStyle1">'+"已提交下周计划"+'</span></div>';
                    }else{
                        noSubmitNextPerson= '<div>下周计划： <span class="messageStyle">'+"还未提交下周计划"+'</span></div>';
                    }
                    message = noSubmitPerson + noSubmitNextPerson;
                }else{
                    for(var i=0;i<that.weekNoSubmitPerson.length;i++){
                        if(noSubmitPerson.length==0){
                            noSubmitPerson +=that.weekNoSubmitPerson[i].value;
                        }else{
                            noSubmitPerson += ";" + that.weekNoSubmitPerson[i].value;
                        }
                    }
                    for(var j=0;j<that.nextNoSubmitPerson.length;j++){
                        if(noSubmitNextPerson.length==0){
                            noSubmitNextPerson +=that.nextNoSubmitPerson[j].value;
                        }else{
                            noSubmitNextPerson +=";" + that.nextNoSubmitPerson[j].value;
                        }
                    }
                    var weekMessage="";
                    var nextMessage="";
                    if(noSubmitPerson.length==0){
                        weekMessage='<div>本周周报： <span class="messageStyle1">'+'全部提交'+'</span></div><br>';
                    }else{
                        weekMessage='<div>本周周报： <span class="messageStyle">'+noSubmitPerson+'</span> 未提交本周周报</div><br>';
                    }
                    if(noSubmitNextPerson.length==0){
                        nextMessage='<div>下周计划： <span class="messageStyle1">'+'全部提交'+'</span></div>';
                    }else{
                        nextMessage='<div>下周计划： <span class="messageStyle">'+noSubmitNextPerson+'</span>  未提交下周计划</div>';
                    }

                    var message = weekMessage + nextMessage;
                }

                that.$notify({
                    title: '提醒',
                    message: message,
                    dangerouslyUseHTMLString:true,
                    offset: 50,
                    // duration: 0
                });
            },
            caculatePerson(){
                debugger;
                let that = this;
                //填写本周周报人数
                var arr = new Array();
                for(var i = 0;i<that.weekDetail.productWeek.length;i++){
                    if(arr.length==0){
                        var userInfo = that.weekDetail.productWeek[i].userInfo;
                        for(var j=0;j<userInfo.length;j++){
                            arr.push(userInfo[j])
                        }
                    }else{
                        var userInfo = that.weekDetail.productWeek[i].userInfo;
                        for(var k=0;k<userInfo.length;k++){
                            var count =1;
                            for(var j=0;j<arr.length;j++){
                                {
                                    if(userInfo[k].code==arr[j].code){
                                        break;
                                    }else{
                                        if(count==arr.length){
                                            arr.push(userInfo[k]);
                                            break;
                                        }else{
                                            ++count;
                                        }

                                    }
                                }
                            }
                        }
                    }
                }
                for(var i =0;i<that.weekDetail.projectWeek.length;i++){
                    if(arr.length==0){
                        var userInfo = that.weekDetail.projectWeek[i].userInfo;
                        for(var j=0;j<userInfo.length;j++){
                            arr.push(userInfo[j])
                        }
                    }else{
                        var userInfo = that.weekDetail.projectWeek[i].userInfo;
                        for(var k=0;k<userInfo.length;k++){
                            var count =1;
                            for(var j=0;j<arr.length;j++){
                                if(userInfo[k].code==arr[j].code){
                                    break;
                                }else{
                                    if(arr.length==count){
                                        arr.push(userInfo[k])
                                    }else{
                                        ++count;
                                    }
                                }
                            }
                        }
                    }
                }

                //填写下周计划人数
                var nextArr = new Array();
                for(var i = 0;i<that.weekDetail.nextProductWeek.length;i++){
                    if(nextArr.length==0){
                        var userInfo = that.weekDetail.nextProductWeek[i].userInfo;
                        for(var j=0;j<userInfo.length;j++){
                            nextArr.push(userInfo[j])
                        }
                    }else{
                        var userInfo = that.weekDetail.nextProductWeek[i].userInfo;
                        for(var k=0;k<userInfo.length;k++){
                            var count =1;
                            for(var j=0;j<nextArr.length;j++){
                                if(userInfo[k].code==nextArr[j].code){
                                    break
                                }else{
                                    if(nextArr.length==count){
                                        nextArr.push(userInfo[k]);
                                    }else{
                                        ++count;
                                    }
                                }
                            }
                        }
                    }
                }
                for(var i =0;i<that.weekDetail.nextProjectWeek.length;i++){
                    if(nextArr.length==0){
                        var userInfo = that.weekDetail.nextProjectWeek[i].userInfo;
                        for(var j=0;j<userInfo.length;j++){
                            nextArr.push(userInfo[j])
                        }
                    }else{
                        var userInfo = that.weekDetail.nextProjectWeek[i].userInfo;
                        for(var k=0;k<userInfo.length;k++){
                            var count =1;
                            for(var j=0;j<nextArr.length;j++){
                                if(userInfo[k].code==nextArr[j].code){
                                    break
                                }else{
                                    if(nextArr.length==count){
                                        nextArr.push(userInfo[k])
                                    }else{
                                        ++count;
                                    }
                                }
                            }
                        }
                    }
                }
                debugger
                that.weekSubmitCount=arr.length;
                that.weekNoSubmitCount=that.formData.userAll.length-arr.length;
                that.NextSubmitCount=nextArr.length;
                that.NextNoSubmitCount=that.formData.userAll.length-nextArr.length;
                that.weekNoSubmitPerson=[];
                that.nextNoSubmitPerson=[];

                for(var i=0;i<that.formData.userAll.length;i++){
                    if(arr.length==0){
                        that.weekNoSubmitPerson=that.formData.userAll;
                    }else{
                        for(var j=0;j<arr.length;j++){
                            if(that.formData.userAll[i].code == arr[j].code){
                                break;
                            }else{
                                if(arr.length==j+1){
                                    that.weekNoSubmitPerson.push(that.formData.userAll[i]);
                                    break;
                                }else{
                                    continue;
                                }

                            }
                        }
                    }
                }
                for(var i=0;i<that.formData.userAll.length;i++){
                    if(nextArr.length==0){
                        that.nextNoSubmitPerson=that.formData.userAll;
                    }else{
                        for(var j=0;j<nextArr.length;j++){
                            if(that.formData.userAll[i].code == nextArr[j].code){
                                break;
                            }else{
                                if(nextArr.length==j+1){
                                    that.nextNoSubmitPerson.push(that.formData.userAll[i]);
                                    break;
                                }else{
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
    },
        mounted() {
            debugger;
            let that=this;
            Vue.prototype.quitLogin=false;
            that.nowWeek();
            that.formData.projectAll=JSON.parse(that.STORAGE.getItem("projectAll"));
            that.formData.productAll=JSON.parse(that.STORAGE.getItem("productAll"));
            that.formData.userAll = JSON.parse(that.STORAGE.getItem("userAll"));
            that.roleId=JSON.parse(that.STORAGE.getItem("roleIdList"))[0]['id'];

        },

    }
</script>

<style scoped>
    .headerCoster{
        height: 59px;
        border-top: 1px solid #eee;
        border-bottom: 1px solid #eee;
    }

    .deleteButtonColor{
        color: red;
    }

    .letBorder{
        border-left: #6aabe6 solid 1px;
    }
    /*.el-table th{*/
    /*    background-color:red !important;*/
    /*    color: white;*/
    /*}*/

    .def-el-input{
        -webkit-appearance: none;
        background-color: #fff;
        background-image: none;
        border-radius: 4px;
        border: 1px solid #dcdfe6;
        box-sizing: border-box;
        color: #606266;
        display: inline-block;
        font-size: inherit;
        height: 40px;
        line-height: 40px;
        outline: none;
        padding: 0 15px;
        width: 35%;
    }

    .cardWidth{
        width: 100%;
    }
    .el-select{
        width: 100%;
    }
</style>